package main

import (
	"fmt"
	"ruoyi/infrastructure/persistence"

	"github.com/gin-contrib/pprof"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	_ "runtime/pprof"
	"ruoyi/config"
	_ "ruoyi/docs"
	"ruoyi/routers"
	"strconv"
)

func main() {
	// 初始化配置文件
	config.InitAppConfig("./config.yaml")
	systemRepositories, monitorRepositories, _ := persistence.MysqlInit()

	persistence.InitClient()

	r := routers.Init(systemRepositories, monitorRepositories)
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// 注册pprof路由  网址打开(端口取config.Server.Port)：http://localhost:8080/debug/pprof/
	pprof.Register(r)

	if err := r.Run(":" + strconv.Itoa(config.Server.Port)); err != nil {
		fmt.Printf("startup service failed, err:%v\n\n", err)
	}
}
